package com.intelligence.device.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligence.device.manager.service.DeviceService;
import com.intelligence.device.manager.service.MeasurementUnitService;
import com.intelligence.entity.pojo.Device;
import com.intelligence.entity.pojo.MeasurementUnit;
import com.intelligence.entity.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用的增删改页面
 *
 * @Author : RulerWood
 * @Data : 2024/6/3 - 15:56
 */
@RestController
@RequestMapping("/device/measurementUnit")
public class MeasurementUnitController {

    @Autowired
    private MeasurementUnitService measurementUnitService;

    /**
     * 获取数据列表
     *
     * @param offset   当前页数
     * @param pageSize 每页条目数
     * @return
     */
    @GetMapping("/pageMeasurementUnit")
    public Result<Page<MeasurementUnit>> pageMeasurementUnit(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
                                                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return Result.build(measurementUnitService.page(new Page<>(offset, pageSize)), 200, "获取设备日志列表成功");
    }


    @GetMapping("/listMeasurementUnit")
    public Result<List<MeasurementUnit>> listMeasurementUnit() {
        return Result.build(measurementUnitService.list(), 200, "获取设备日志列表成功");
    }

    /**
     * 获取单个对象
     * @param id    对象主键
     * @return
     */
    @GetMapping("/getMeasurementUnit/{id}")
    public Result<MeasurementUnit> getMeasurementUnit(@PathVariable(value = "id") Long id) {
        return Result.build(measurementUnitService.getById(id), 200, "获取设备日志成功");
    }


    /**
     * 数据的新增
     *
     * @param measurementUnit 保存对象
     * @return
     */
    @PostMapping("/saveMeasurementUnit")
    public Result saveMeasurementUnit(@RequestBody MeasurementUnit measurementUnit) {
        measurementUnitService.save(measurementUnit);
        return Result.build(null, 200, "保存设备日志成功");
    }

    /**
     * 数据的修改
     *
     * @param measurementUnit 修改对象
     * @return
     */
    @PutMapping("/updateMeasurementUnit")
    public Result updateMeasurementUnit(@RequestBody MeasurementUnit measurementUnit) {
        measurementUnitService.updateById(measurementUnit);
        return Result.build(null, 200, "更新设备日志成功");
    }

    /**
     * 删除某条数据
     *
     * @param id 数据主键
     * @return
     */
    @DeleteMapping("/deleteMeasurementUnit/{id}")
    public Result deleteMeasurementUnit(@PathVariable(value = "id") Integer id) {
        measurementUnitService.removeById(id);
        return Result.build(null, 200, "删除设备日志成功");
    }

}
